Repository navigation
fix(stacked_did): anticipation-aware clean controls and survey-inference fixes - #923
Conversation
Overall assessment⛔ Blocker — The new Plotly renderer can display a confidence interval that the fitted survey design withheld. Executive summary
Methodology
Code Quality
PerformanceNo findings. Maintainability
Tech Debt
SecurityNo findings. Documentation/TestsThe release fragment follows the repository convention and passed the changelog compiler check. Path to Approval
|
…nce fixes - Clean controls: a later adopter responds from A_s - anticipation, so the cutoff is A_s > a + kappa_post + anticipation (plus kappa_pre under "strict"), in the inclusion check and the stack builder. A noiseless panel with a true effect of 2 gave 1.5 at event time 2 and 1.875 overall. - Results record the rule (control_cutoff_includes_anticipation); the target-parameter description and the BusinessReport assumption block state the cutoff a fit used and label an unrecorded one unverified. - Survey: a fit is refused when the anticipation term takes a sampled unit out of the stack; a design without a psu column uses the original unit as PSU (never unit-by-sub-experiment pairs) and validates it like an explicit PSU; zero survey degrees of freedom gives NaN inference instead of t(1). - Registry notes, backlog rows, bundled guide and changelog.
…ined in plots and reports - plot_event_study on a results object rebuilt intervals from the SE for rows whose stored interval is NaN with a finite SE (a zero-df survey fit). Those rows now plot as points with no interval on every channel. - BusinessReport names the variance method of a zero-df survey fit and says no interval is available. - StackedDiD shares one window predicate between trimming and the survey guard; guide wording says PSUs or strata can leave the design.
…an interval; describe the inference a zero-df fit stored - The Plotly band skipped a row with no interval and filled across it. It is now one polygon per run of rows that carry an interval; a reference row does not break the band. - BusinessReport's zero-df caveat follows the stored interval and p-value: "no interval is available" only when the fit stored none.
…a valid interval stays visible Splitting the Plotly band at rows without an interval can leave a row with a valid interval on its own; a one-point polygon has no area and was invisible. Registry and changelog follow the renderer.
…s on both routes and all three options
…oute; band bridges only real constraints; replicate designs without a df - The raw dCDH route recomputed intervals from the SE for effects and placebos whose stored interval is NaN; the one-row bar made that visible. Those rows now plot with no interval. - The Plotly band continues only across a normalization constraint (a reference row with no uncertainty), not across a row merely styled as the reference by the -1 fallback. - BusinessReport treats a replicate design that records no df and stored no interval as undefined-df.
…-chosen reference Reference styling comes from the raw route's -1 fallback when the producer marks no reference; under a varying base that row is an estimated placebo, whatever its SE. The band now continues across a row without an interval only when the caller normalized on it or the producer declared it (container marks, an is_reference row, a reference_period attribute, the dCDH reference).
…nstraint only for the horizon it names A reference a results object declares between horizons (-0.5) was cast to int and landed on event time 0, an estimated effect, which was then styled as the reference and, with the new band rule, bridged. The label is kept as given and verified against the plotted horizon.
…t round-trip; end-to-end plot test on a fitted model
…oss numeric types Plain == converts an integer reference to float, so a float horizon one away from it beyond 2**53 compared equal and was styled, and bridged, as the reference. All reference-label comparisons in plot_event_study go through one exact comparator (rationals at native precision). The fitted test now uses a fixture whose shared reference is -0.5.
…rence fix Keep only: a results object passed directly no longer has intervals rebuilt from the SE for rows whose stored interval is NaN (generic and dCDH routes). The Plotly band splitting, the one-row bar, reference provenance and exact label comparison are taken back out; the Plotly band behavior and the raw route's reference handling are logged in TODO.md for their own change.
… the full sample; partial intervals; interval vs significance in the report - StackedDiD: a design naming no PSU has the unit declared as PSU before the design is resolved on the supplied panel, so an FPC below a stratum's unit count raises even when trimming would bring the stack under it. - plot_event_study: a stored interval with one missing or NaN endpoint is undefined too; a row storing no interval keeps the recomputed one. - BusinessReport: interval availability follows the stored bounds and significance availability the stored p-value, separately.
…ot that it does not apply; wider plot tests
ddb2629 to
acd102d
Compare
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment
Executive summary
Methodology
Code Quality
PerformanceNo findings. MaintainabilityNo open findings. The prior alpha-caveat finding is resolved for both zero and unrecorded replicate degrees of freedom. Tech Debt
SecurityNo findings. Documentation/TestsThe changelog validator passed, and all changed Python files compiled. Isolated checks with test doubles reproduced the empty-input exception and verified the dCDH plotting and report behavior. The environment lacked the dependencies for the full test suite and could not reach the NBER PDF. The methodology cross-check used the Registry, the checked-in R reference, and the repository’s paper reviews. Path to Approval
|
…re the survey design is resolved
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment✅ Looks good. The prior P1 is resolved. Empty panels now raise a descriptive Executive summary
Methodology
Code QualityNo open findings. An isolated check confirmed that all four empty-panel configurations exit before the survey resolver is reached. PerformanceNo findings. MaintainabilityNo open findings. The shared report helper uses the fitted result’s cutoff record and labels the earlier rule unverified when that record is absent. Tech Debt
SecurityNo findings. Documentation/TestsThe changelog fragment passed validation, all nine changed Python files compiled, and isolated checks passed for the empty-panel guard, cutoff boundaries, NaN inference, plot inputs, and report wording. The environment lacked the scientific Python dependencies for the full suite and could not reach the NBER PDF. The methodology cross-check used the Registry, the checked-in R reference, and the repository’s Binder paper review. |
Summary
Split out of #920 (the Staggered family tutorials), whose review surfaced these
StackedDiDdefects. All of them are onmaintoday; #920 goes back to documentation only once this merges.Clean controls under anticipation
anticipation > 0, a later adopter stayed in an event's control pool through periods in which it was already responding. On a noiseless balanced panel (cohorts 3, 6 and never-treated, an effect of 2 starting one period before adoption,kappa_pre = kappa_post = 2,anticipation = 1) the fit returned 1.5 at event time 2 and 1.875 overall; both are now 2 exactly.A_s > a + kappa_post + anticipation, pluskappa_preunder"strict", applied by one helper in the inclusion check and the stack builder. Fits withanticipation=0or never-treated controls are unchanged, and the R-parity panels regenerate byte-identical.StackedDiDResults.control_cutoff_includes_anticipationrecords the rule (Trueon every fit,Noneon a result saved by an earlier version).BusinessReportandDiagnosticReportstate the adjusted cutoff only when it is recorded, and otherwise show the earlier cutoff labelled unverified.Survey inference (Taylor linearization)
anticipationterm leaves a later cohort out of every sub-experiment raisesNotImplementedError. The design is re-resolved on the stacked rows, so that cohort's PSUs or strata can leave the variance (stratified census: SE 0.136 with 9 df where the full design gives SE 0 with 15 df).psuuses each original unit as its PSU for eitherclustersetting. Undercluster="unit_subexp"the fit used (unit, sub-experiment) pairs, which duplicate sampled units: SE 0 with 21 df where the sampled units give SE 0.07906 with 15. Standard errors change for survey fits that combinedcluster="unit_subexp"with a design naming nopsu.psugets, against the full supplied sample and not only the units that reach the stack. A single-unit stratum warns, and an FPC below a stratum's unit count raises.n_PSU - n_strata = 0the fit returns NaN t-statistics, p-values and intervals with a warning. It clamped the df to 1 and reported t(1) inference (p = 0.079 on a six-unit, six-stratum panel).fit()on a panel with no rows raises a descriptiveValueError(it raised "cannot convert float NaN to integer", orIndexErrorwith an FPC column).Consumers of undefined inference
plot_event_study(results)rebuilt intervals from the standard error for rows whose stored interval is missing or NaN at either endpoint. Those rows now get no interval, on the generic route and the dCDH route (effects and placebos), as theaggregate("event_study")container already did.BusinessReport's zero-df caveat follows what the fit stored: interval availability from the stored bounds, significance from the stored p-value.Not fixed here (logged in
TODO.md)SunAbrahamhas the same clamp to 1 at zero survey df. Removing it alone leaves its cell-level inference on a normal-theory fallback, so it needs its own change.-1fallback, theint()cast of a declared reference, mixed-type horizon labels) is unchanged. Both are documented in the Registry and tracked for a dedicated plotting change.Methodology references (required if estimator / math changes)
docs/methodology/REGISTRY.mdas- **Note (clean controls under anticipation):**,- **Note (survey PSU without an explicit psu):**and- **Note (zero survey degrees of freedom):**in the StackedDiD section, and- **Note (undefined stored inference on the raw-results routes):**under Event Study Plotting.Validation
tests/test_stacked_did.py(TestCleanControlAnticipation,TestCleanControlAnticipationSurvey),tests/test_business_report.py,tests/test_target_parameter.py,tests/test_visualization.py(TestPlotEventStudyUndefinedStoredInference,TestPlotEventStudyRawDCDHUndefinedInference,TestPlotEventStudyFittedUndefinedRow). The clean-control regression tests fail without the fix. 4535 passed on each backend across the StackedDiD, survey, dCDH, SunAbraham, plotting, reporting, design and guard test files before the last small commit (report wording and wider plot tests), whose files pass on both backends.-Wbuild passes locally.Security / privacy
Changelog
changelog.d/20261127-stacked-did-anticipation-survey.md)